﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using RemoteBank.Entity;
using RemoteBank.BLL;

namespace RemoteBank.GUI
{
    public partial class frmMain : Form
    {
        private List<Account> listAccount;
        private SqlDataReader dr;
        private bool isLogin = false;
        private User user;

        internal List<Account> ListAccount
        {
            get { return listAccount; }
            set { listAccount = value; }
        }
       

        
        public frmMain()
        {
            InitializeComponent();
        }
        public bool IsLogin
        {
            get { return isLogin; }
            set { isLogin = value; }
        }
        internal User User
        {
            get { return user; }
            set { user = value; }
        }
        public void CreateLoginForm()
        {
            
                frmLogin login = new frmLogin(this);
                login.MdiParent = this;
                login.StartPosition = FormStartPosition.CenterScreen;
                login.Show();
          
        }
        public void checkEnable()
        {
            foreach (Account acc in listAccount)
            {
               

                if (acc.AccountType == 1)
                {
                    receivingToolStripMenuItem.Enabled = true;
                    receivingToolStripMenuItem.Enabled = true;
                }
                else if (acc.AccountType == 2)
                {
                    transferToolStripMenuItem.Enabled = true;
                    transferToolStripMenuItem1.Enabled = true;
                }
                else if (acc.AccountType == 3)
                {
                    withdrawlsToolStripMenuItem.Enabled = true;
                    withdrawlsToolStripMenuItem1.Enabled = true;
                }
                //lvwAccountInformation.Items.Add(l);
                //i++;
            }
        }
       
            
       
        private void frmMain_Load(object sender, EventArgs e)
        {
            this.CreateLoginForm();
        }

        private void fileToolStripMenuItem_Click(object sender, EventArgs e)
        {
            //this.CreateAccountForm();
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            Close();
        }

        private void accountInformationToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.CloseForm();
            if (this.isLogin)
            {
                frmAccount account = new frmAccount(this);
                account.MdiParent = this;
                //account.StartPosition = FormStartPosition.CenterScreen;
                account.WindowState = FormWindowState.Maximized;

                account.Show();
            }
            else {
                this.CreateLoginForm();
            }
        }
        public void CloseForm()
        {
            int child = MdiChildren.Length;
            for (int i = 0; i < child; i++)
            {
                MdiChildren[i].Dispose();
            }

        }

        private void logOutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            
            this.CloseForm();
            isLogin = false;
            this.CreateLoginForm();
        }
    }
}
